const config = require('../src/utils/config')

const { apiPrefix } = config

let performancesOfDepartment = []

for (let i = 0; i < 10; i++) {
  let id = i + 1
  performancesOfDepartment.push({
    id: id,
    department: {
      name: '部门' + id
    },
    orderAmount: id,
    orderCount: id,
    signPerformance: id,
    signOrderCount: id,
    followPerformance: id,
    followCount: id,
    backPerformance: id,
    backCount: id
  })
}

module.exports = {
  [`GET ${apiPrefix}/performancesOfDepartment/query`](req, res) {
    const { query } = req
    let { size, current, ...other } = query
    size = size || 10
    current = current || 1

    let newData = performancesOfDepartment
    for (let key in other) {
      if ({}.hasOwnProperty.call(other, key)) {
        newData = newData.filter((item) => {
          if ({}.hasOwnProperty.call(item, key)) {
            return String(item[key]).trim().indexOf(decodeURI(other[key]).trim()) > -1
          }
          return true
        })
      }
    }

    res.status(200).json({
      code: 0,
      message: "successed",
      data: {
        records: newData,
        total: newData.length,
      },
    })
  }
}
